package com.hclc.entity.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 端口
 * @ClassName PortTypeEnum
 * @Author: yurj
 * @Mail：1638234804@qq.com
 * @Date: Create in 17:55 2020/7/27
 * @version: 1.0
 */
public enum PortTypeEnum implements IEnum<Integer> {
    APP(1, "应用"),

    BACKSTAGE(2, "后台");

    @JsonValue
    @EnumValue
    private final int code;


    private final String desc;

    PortTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static PortTypeEnum find(String desc) throws IllegalArgumentException {
        for (PortTypeEnum model : PortTypeEnum.values()) {
            if (model.getDesc().equals(desc)) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }

    @JsonCreator
    public static PortTypeEnum find(int code) throws IllegalArgumentException {
        for (PortTypeEnum model : PortTypeEnum.values()) {
            if (model.getValue() == code) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
}
